package se.webbzon.boltzmann.game.object.waypoint;

import javax.vecmath.Point3d;

import se.webbzon.boltzmann.game.object.player.AbstractPlayerCharacter;

public class PlayerDirection extends AbstractDirection {
	
	// The input blocker of the player
	private Object blocker;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new player direction for the given player where a 
	 * direction start point of a path is provided. **/
	public PlayerDirection(AbstractPlayerCharacter player, Waypoint start) {
		super(player,start);
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override protected void moveTo(Point3d position) {
		AbstractPlayerCharacter player = 
				(AbstractPlayerCharacter) getDirectionTaker();
		final double direction = Math.atan2(position.getZ() - player.getZ(), 
											position.getX() - player.getX());
		player.setMotion(-direction, player.getGroundSpeed());
	}

	@Override protected void onBegin() {
		AbstractPlayerCharacter player = 
				(AbstractPlayerCharacter) getDirectionTaker();
		blocker = player.containBlocker();
	}

	@Override protected void onEnd() {
		AbstractPlayerCharacter player = 
				(AbstractPlayerCharacter) getDirectionTaker();
		player.setMotion(0, 0);
		player.releaseBlocker(blocker);
	}

}
